//
//  LFTopView.m
//  LoveFruit
//
//  Created by 马海江 on 16/9/24.
//  Copyright © 2016年 张令林. All rights reserved.
//

#import "LFTopView.h"

@interface LFTopView ()
@end

@implementation LFTopView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.image = [UIImage imageNamed:@"v2_my_avatar_bg"];
//    imageView.userInteractionEnabled = YES;
    [self addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@175);
    }];
    
    // 设置按钮
    UIButton *settingButton = [[UIButton alloc] init];
    [settingButton setImage:[UIImage imageNamed:@"v2_my_settings_icon"] forState:UIControlStateNormal];
    [self addSubview:settingButton];
    [settingButton sizeToFit];
    [settingButton addTarget:self action:@selector(settBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [settingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(19);
        make.right.equalTo(self).offset(-19);
    }];
    
    // 头像
    UIImageView *headerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"v2_my_avatar"]];
    [self addSubview:headerView];
    [headerView sizeToFit];
    headerView.layer.cornerRadius = (imageView.bounds.size.width * 1.0) / 2;
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(53);
        make.left.equalTo(self.mas_left).offset(15);
    }];
    
    // 账号
    UILabel *numberLabel = [[UILabel alloc] init];
    numberLabel.text = @"15531876900";
    numberLabel.textColor = [UIColor whiteColor];
//    numberLabel.font = [UIFont systemFontOfSize:14];
    [numberLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
    [self addSubview:numberLabel];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView.mas_right).offset(15);
        make.top.equalTo(self).offset(55);
    }];
    
    // VIPButton
    UIButton *VIPButton = [[UIButton alloc] init];
    [VIPButton setBackgroundImage:[UIImage imageNamed:@"icon_member"] forState:UIControlStateNormal];
//    VIPButton.titleLabel.text = @"   注册会员";
//    VIPButton.titleLabel.textColor = [UIColor redColor];
    [VIPButton setTitle:@"     注册会员" forState:UIControlStateNormal];
    VIPButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [VIPButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self addSubview:VIPButton];
    [VIPButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView.mas_right).offset(15);
        make.top.equalTo(numberLabel.mas_bottom).offset(10);
    }];
    
    // 收藏商品
    UIButton *goodsButton = [[UIButton alloc] init];
    [goodsButton setImage:[UIImage imageNamed:@"v2_my_goodsCollection"] forState:UIControlStateNormal];
    [goodsButton setTitle:@" 商品收藏" forState:UIControlStateNormal];
    goodsButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [goodsButton addTarget:self action:@selector(goodsButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:goodsButton];
    [goodsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-[UIScreen mainScreen].bounds.size.width / 4);
        make.centerY.equalTo(self.mas_bottom).offset(-20);
    }];
    
    // 中间线
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 2 - 0.5, 145, 1, 20)];
    lineView.backgroundColor = [UIColor whiteColor];
    [self addSubview:lineView];
    
    // 收藏店铺
    UIButton *shopButton = [[UIButton alloc] init];
    [shopButton setImage:[UIImage imageNamed:@"v2_my_storeCollection"] forState:UIControlStateNormal];
    [shopButton setTitle:@" 店铺收藏" forState:UIControlStateNormal];
    shopButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [shopButton addTarget:self action:@selector(shopButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:shopButton];
    [shopButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset([UIScreen mainScreen].bounds.size.width / 4);
        make.centerY.equalTo(self.mas_bottom).offset(-20);
    }];
    
    // 会员按钮
    UIButton *memberButton = [[UIButton alloc] initWithFrame:CGRectMake(95, 55, 270, 65)];
    [memberButton addTarget:self action:@selector(memberButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:memberButton];
}
// 点击事件
- (void)settBtnClick{
    NSLog(@"设置按钮点击了");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationSettBtnClick" object:nil userInfo:nil];
}
- (void)memberButtonClick{
    NSLog(@"进入VIP界面");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationMemberButtonClick" object:nil userInfo:nil];
}
- (void)goodsButtonClick{
    NSLog(@"商品收藏");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationGoodsButtonClick" object:nil userInfo:nil];
}
- (void)shopButtonClick{
    NSLog(@"店铺收藏");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationShopButtonClick" object:nil userInfo:nil];
}
@end
